/**
 * 
 */
package com.et114.modules.org.cells;

import java.util.Collection;
//import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.extremecomponents.table.bean.Column;
import org.extremecomponents.table.cell.Cell;
import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.util.HtmlBuilder;

//import com.et114.components.acegi.Constants;
//import com.et114.modules.org.services.OrgFactory;
import com.et114.modules.org.vo.FuncComponentVo;

/**
 * @author guanhw
 */
public class FuncCompIdMultipleSelectedCell implements Cell {

	protected  Log logger = LogFactory.getLog( this.getClass ( ) );
	public final static String	SELECTED_PRESIDENTS	= "SELECTED_PRESIDENTS";
	public final static String	SELECTED			= "SELECTED";
	public final static String	UNSELECTED			= "UNSELECTED";

	public String getExportDisplay ( TableModel model , Column column ) {
		return null;
	}

	/**
	 * 
	 */
	public String getHtmlDisplay ( TableModel model , Column column ) {
		int count  = 0 ; 
		HtmlBuilder html = new HtmlBuilder();
		html.td ( 0 ).xclose ( ) ;
		try {
			FuncComponentVo bean = ( FuncComponentVo ) model.getCurrentRowBean(  );
			count  = bean.getCountRel ( ).intValue ( ) ; 
			String scn = "deleteId";
			String id = bean.getFuncElementId ( ).toString ( ) ; 
			Collection selectedPresidentsIds = ( Collection ) model.getContext().getSessionAttribute( SELECTED_PRESIDENTS );
			if ( selectedPresidentsIds != null	&& selectedPresidentsIds.contains( id ) ) {
				html.input( "checkbox" ).name( scn ).value( id );
				html.xclose();									
			} else {
				html.input( "checkbox" ).name( scn ).value(	id );
				if ( count > 0  ) {
					html.disabled ( );
				}					
					
				html.xclose();
			}
		} catch ( Exception e ) {
			logger.error (  e.getMessage ( ) , e ) ;
		}
		html.tdEnd ( );
		return html.toString();
	}	
}
